<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>count:{{count}}</p>
      <p>doubleCount:{{doubleCount}}</p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
    <script src="https://unpkg.com/vuex@3.1.3/dist/vuex.js"></script>
    <script>
      var counter1 = {
        namespaced: true, //启用命名空间
        state: { count: 1 },
        getters:{
          doubleCount(state){
            return state.count*2;
          }
        },
        mutations: {
          increase(state) {
            state.count++;
          },
        },
        actions: {
          increaseInAction({ commit }) {
              commit("increase");
            }
        }
      };
      var counter2 = {
        namespaced: true, //启用命名空间
        state: { count: 1 },
        getters:{
          doubleCount(state){
            return state.count*2;
          }
        },
        mutations: {
          increase(state) {
            state.count++;
          },
        },
        actions: {
          increaseInAction({ commit }) {
              commit("increase");
            }
        }
      };
      var store = new Vuex.Store({
        modules: { counter1,counter2 },
      });
      const {mapState:mapState1,mapGetters:mapGetters1} = Vuex.createNamespacedHelpers('counter1');
      const {mapState:mapState2,mapGetters:mapGetters2} = Vuex.createNamespacedHelpers('counter2');
      var vm = new Vue({
        store,
        el:'#app',
        computed:{
          ...mapState1(['count']),
          ...mapGetters1(['doubleCount']),

          ...mapState2(['count']),
          ...mapGetters2(['doubleCount']), 
        }
      })
    </script>
  </body>
</html>
